﻿using System;
using System.Linq;
using System.Windows.Forms;
using OSS.BIM.UI.Controls;
using DevExpress.XtraEditors;
using ZFGK.Utility;

namespace OSS.BIM.UI.Forms
{
    public partial class PropertyForm : XtraForm
    {
        public PropertyForm(string key, string val, bool doAdd)
        {
            InitializeComponent();
            Key = key;
            Value = val;
            DoAdd = doAdd;
        }

        public string Key { get; set; }
        public string Value { get; set; }
        public bool DoAdd { get; set; }

        private void PropertyForm_Load(object sender, EventArgs e)
        {
            txeName.Text = Key;
            meValue.Text = Value;
            txeName.Enabled = DoAdd;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txeName.Text.Trim()))
            {
                ZfMessageUtil.ShowError("名称不能为空!");
                txeName.Focus();
                return;
            }
//             if (string.IsNullOrEmpty(meValue.Text.Trim()))
//             {
//                 ZfMessageUtil.ShowError("名称不能为空!");
//                 meValue.Focus();
//                 return;
//             }

            Key = txeName.Text.Trim();
            Value = meValue.Text.Trim();

            if (DoAdd && PropertiesGridControl.Instance.Properties.Any(d => d.Name == Key || d.DiaplayLable == Key))
            {
                ZfMessageUtil.ShowError("已存在相同的名称!");
                txeName.Focus();
                return;
            }

            DialogResult = DialogResult.OK;
        }
    }
}